package com.itehima.Buffer;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Prac01 {

    public static void main(String[] args) throws IOException {

        //关于文本排序
        BufferedReader br = new BufferedReader(new FileReader("20240417\\in.txt"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("20240417\\out.txt"));
        String line;
        ArrayList<String> list=new ArrayList<>();
        //读取in.out中的古诗，将每一行字符串都存入字符串容器
        while ((line=br.readLine())!=null) {
            list.add(line);
        }
        //对字符串容器中的序号和文字进行切割，得到序号进行自定义排序
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {

                return o1.charAt(0)-o2.charAt(0);
            }
        });
        //讲解过重新写入out.txt
        for (String s : list) {
            bw.write(s);
            bw.newLine();//再写入一个换行
        }
        bw.close();
        br.close();
    }
}
